package com.tarena.lbs.marketing.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.marketing.web.service.CouponService;
import com.tarena.lbs.pojo.marketing.param.CouponParam;
import com.tarena.lbs.pojo.marketing.query.CouponQuery;
import com.tarena.lbs.pojo.marketing.vo.CouponVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class CouponController {
    @Autowired
    private CouponService couponService;
    @PostMapping("/admin/marketing/coupon/info/list")
    public Result<PageResult<CouponVO>> pageList
            (@RequestBody CouponQuery query)throws BusinessException{
        return new Result<>(couponService.pageList(query));
    }
    //优惠券表单新增
    @PostMapping("/admin/marketing/coupon/info/save")
    public Result<Void> save(@RequestBody CouponParam couponParam)
        throws BusinessException{
        long start=System.currentTimeMillis();
        couponService.save(couponParam);
        long end=System.currentTimeMillis();
        log.info("优惠券新增耗时:{}MS",end-start);
        return Result.success();
    }
    //手机小程序 查询一个活动中的优惠券详情
    @GetMapping("/admin/marketing/coupon/info/detail/{id}")
    public Result<CouponVO> detail(@PathVariable("id") Integer id){
        return new Result<>(couponService.detail(id));
    }
}
